<template>
    <el-container class="main">
        <el-header>个人博客系统 <el-button @click="logout">退出</el-button></el-header>
        <el-container>
            <el-aside :width="!isCollapse?'200px':'56px'">
                <div class="menu-collapse" @click="toCollapse">|||</div>
                <el-menu
                :default-active="menuActive"
                :collapse-transition="false"
                class="el-menu-vertical-demo"
                background-color="#373d41"
                text-color="#fff"
                :router="true"
                :unique-opened="true"
                @select="menuSelect"
                :collapse="isCollapse"
                active-text-color="#ffd04b">
                    <el-submenu :index="1+''">
                        <template slot="title">
                        <i class="el-icon-s-custom"></i>
                        <span>用户管理</span>
                        </template>
                        <el-menu-item-group>
                            <el-menu-item :index="'/users'"><i class="el-icon-menu"></i>用户列表</el-menu-item>
                        </el-menu-item-group>
                    </el-submenu>
                    <el-submenu :index="2+''">
                        <template slot="title">
                        <i class="el-icon-document-copy"></i>
                        <span>博客管理</span>
                        </template>
                        <el-menu-item-group>
                            <el-menu-item :index="'/blogs'"><i class="el-icon-menu"></i>博客列表</el-menu-item>
                        </el-menu-item-group>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <el-main>
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>

<script>
export default {
    created(){
        //
        this.menuActive = window.sessionStorage.getItem("menu");
    },
    data(){
        return {
            menuActive:'',
            isCollapse:false,
        }
    },
    methods:{
        menuSelect(index){
            this.menuActive = index;
            window.sessionStorage.setItem("menu",index);
        },
        logout(){
            window.sessionStorage.clear();
            this.$router.push("/login");
        },
        toCollapse(){
            this.isCollapse = !this.isCollapse;
        }
    }
}
</script>

<style scoped>
.main {
    width: 100%;
    height: 100%;
    position: absolute;
}
.el-header {
    background-color: #373d41;
    line-height: 60px;
    font-size: 18px;
    color: white;
    position: relative;
}
.el-header .el-button{
    position: absolute;
    right: 10%;
    bottom: 15%;
}
.el-aside {
    background-color: #373d41;
}
.el-menu {
    border-right: 0;
}
.menu-collapse {
    width: 100%;
    height: 20px;
    color: white;
    text-align: center;
    cursor: pointer;
    background-color: #4a5064;
}
</style>